<template>
    <div>
        <slot></slot>
    </div>
</template>

<script>
    export default {
        name: "KForm",
        provide(){
            return {
                rules: this.rules,
                model: this.model
            }
        },
        props:{
            model:{
                type: Object,
                required: true
            },
            rules:{
                type: Object
            }
        },
        methods: {
            validate(cb) {
                // 这里也是存在耦合性的， 所以需要对children进行查找
                let validates = this.$children.filter(item => item.prop).map(child => child.validate())

                Promise.all(validates).then(() => {
                    cb(true)
                }).catch(() => {
                    cb(false)
                });
            }
        },
    }
</script>

<style scoped>

</style>
